#pragma once

#include <vector>
#include <cmath>
#include "../board/Board.h"
#include "CheckersDefs.h"
#include "MoveData.h"
#include "PiecePosition.h"
#include "../ai/AIPathFinder.h"

using namespace std;

class Checkers
{
public:
	// Standard constructor
	Checkers(void);
	// Constructor used for other calculations
	Checkers(int status, int player, Board* board);

	virtual ~Checkers(void);

	// Get the game board
	Board* GetBoard();

	
	// Move has to check x2, y2 is +- 1||2 spaces depending on if a jump
	// is valid. Move must return move success, and if anything was captured.
	int Move(int x1, int y1, int x2, int y2);

	// Game status
	int GetStatus();

	// Current player (is CHECKERS_PLAYER1 or CHECKERS_PLAYER2
	int GetCurrentPlayer() { return whoseTurnIsIt;}

	// Replaces IsMoveLegal(), if it's legal, the path is returned, otherwise it's null (0)
	Path* FindPathForMove(int x1, int y1, int x2, int y2);

	// Uses the AIPathFinder to see if a move is valid
	// Gets a list of all valid paths ranked by priority (most important at [0])
	vector<Path*> GetMoves();

	// Returns the best possible path
	Path* GetBestPath();

	// Given a path, it follows it
	bool FollowPath(Path* path);

	// [OBSOLETE]Gets the legal moves for the current user, if there are jumps/captures then only
	// those are returned, otherwise EVERY legal move is returned.
	int GetLegalMoves(vector<MoveData*> &legalMoves);

	//Sets the game board
	void SetBoard(Board board){*gameBoard = board;}

	// Clears the vector of moves that were returned by the GetLegalMoves call
	void ClearLegalMoves(vector<MoveData*> & legalMoves);

	// Changes the player's turn
	void ChangePlayerTurn();

private:
	Board* gameBoard;
	int status;
	int movesWithNoCapture;
	int whoseTurnIsIt;
	PiecePosition postCapturePosition;
	AIPathFinder* pathFinderHolder;

	// Player turn helpers
	
	bool CorrectPlayerPieceSelection(int boardValue);

	// General helpers
	bool ValidatePostCaptureStatus(int x, int y);
	bool CanPerformAnotherCapture();
	bool CanPerformCapture(int x, int y);
	bool CanMove(int x, int y);

	// [SHOULD BE PRIVATE - DON"T USE EXTERNALLY use IsPoint] 
	// Update for a single space move or a capture move (1,1) or (2.2)
	bool IsIndividualMoveLegal(int x1, int y1, int x2, int y2);

	// Used in conjunction with GetLegalMoves()
	void CollectCaptures(int x, int y, vector<MoveData*> &legalMoves);
	void CollectMoves(int x, int y, vector<MoveData*> &legalMoves);
};
